<?php
/**
 * 
 * @authors ak (duguyi187@163.com)
 * @date    2016-12-14 17:49:19
 * @version $Id$
 */

// Registering navigation menus.
register_nav_menus( array(
	'primary' => __( '基础菜单', 'ample' ),
	'footer' => __( '底部菜单', 'ample' ),
) );

//自定义文章形式
add_theme_support( 'post-formats', array( 'status', 'aside', 'gallery', 'video' ) );
function rename_post_formats( $safe_text ) {
    if ( $safe_text == '状态' )
        return '协会刊物';
    if ( $safe_text == '日志' )
        return '书画资讯';
    if ( $safe_text == '相册' )
        return '书画作品';
    if ( $safe_text == '视频' )
        return '协会会员';
    return $safe_text;
}
add_filter( 'esc_html', 'rename_post_formats' );

add_action('template_include', 'load_single_template');   
function load_single_template($template) {   
  $new_template = '';   
  if( is_single() ) {   
    global $post;  
    if ( has_post_format( 'status' )) { 
		$new_template = locate_template(array('single-periodical.php' ));   
    }elseif(has_post_format( 'aside' )){
		$new_template = locate_template(array('single-news.php' ));  
	} elseif(has_post_format( 'gallery' )){
		$new_template = locate_template(array('single-image.php' ));  
	} elseif(has_post_format( 'video' )){
		$new_template = locate_template(array('single-member.php' ));  
	}else{
		$new_template = locate_template(array('single.php' ));  
	}
 
  }   
  return ('' != $new_template) ? $new_template : $template;   
}

/*
* 获取当前文章或页面别名的函数
*/
function the_slug() {
    $post_data = get_post($post->ID, ARRAY_A);
    $slug = $post_data['post_name'];
    return $slug;
}

//特色图片
add_theme_support('post-thumbnails');
set_post_thumbnail_size(130, 100, true); 

/*
* 后台文章列表后面显示特色图像
*/
add_filter('manage_posts_columns', 'lei_add_thumb_col');
add_action('manage_posts_custom_column', 'lei_get_thumb_show');
function lei_add_thumb_col($cols) {
    $cols['thumbnail'] = __('Thumbnail');
    return $cols;
}
function lei_get_thumb_show($column_name ) {
    if ( $column_name  == 'thumbnail'  ) {
        echo get_the_post_thumbnail(get_the_ID(),array(100,100));
    }
}

function autoVer($url){
    $ver = mt_rand();
    echo $url.'?v='.$ver;
}

/*
* 后台文章列表后面显示排序
*/
add_filter('manage_posts_columns', 'my_post_sort_columns');
add_action('manage_posts_custom_column', 'my_get_sort_show');
function my_post_sort_columns($cols) {
    $cols['sort'] = __('优先级');
    return $cols;
}
function my_get_sort_show($column_name ) {
    if ( $column_name  == 'sort'  ) {
        echo get_post_meta(get_the_ID(), 'sort', true);
    }
}


add_filter( 'pre_option_link_manager_enabled', '__return_true' );

//删除wp_head()多余的代码
remove_action( 'wp_head', 'feed_links_extra', 3 ); //去除评论feed
remove_action( 'wp_head', 'feed_links', 2 ); //去除文章feed
remove_action( 'wp_head', 'rsd_link' ); //针对Blog的远程离线编辑器接口
remove_action( 'wp_head', 'wlwmanifest_link' ); //Windows Live Writer接口
remove_action( 'wp_head', 'index_rel_link' ); //移除当前页面的索引
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); //移除后面文章的url
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); //移除最开始文章的url
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );//自动生成的短链接
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); ///移除相邻文章的url
remove_action( 'wp_head', 'wp_generator' ); // 移除版本号

remove_action( 'wp_head', 'wp_print_styles', 8 );   
remove_action( 'wp_head', 'wp_print_head_scripts', 9 );   
//remove_action( 'wp_head', 'rel_canonical' );    
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); 

remove_action( 'wp_head', 'print_emoji_detection_script',7 ); 
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
add_action('get_header', 'remove_admin_login_header'); //移除wordpress顶部工具栏css样式media="screen"
function remove_admin_login_header() { 
	remove_action('wp_head','_admin_bar_bump_cb'); 
}
//移除头部多余.recentcomments样式
function Fanly_remove_recentcomments_style() {
    global $wp_widget_factory;
    remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
}
add_action( 'widgets_init', 'Fanly_remove_recentcomments_style' );



/**
 * 图片处理
 */
require get_template_directory() . '/inc/blueimp-gallery.php';


/**
 * 文章
 */
require get_template_directory() . '/inc/read-article.php';